/*
 * 原版接口
 */
import * as server from "@minecraft/server";
/*
 * 彼岸组件
 */
import * as effect_machine from "./effect_machine";
import * as machine_gate from "./machine_gate";
/*
 * 蛋白石组件
 */
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
/**
 * * 进行检测的默认标签
 */
const defaultTag = 'data_tag:magic_tool.series';
/**
 * * 玩家交互组件参数接口
 */
interface INTERACT_COMPONENT {
    /**
     * 方块对象
     */
    block: server.Block;
    /**
     * 方块状态
     */
    state: server.BlockPermutation;
    /**
     * 方块维度
     */
    dimension: server.Dimension;
    /**
     * 玩家对象
     */
    player: server.Player | undefined;
    /**
     * 玩家背包
     */
    container: server.Container | undefined;
    /**
     * 物品对象
     */
    item: server.ItemStack | undefined;
};
/**
 * * 实体交互方块组件
 * 
 * @param source - 方块组件参数
 */
function InteractComponentTrigger(source: server.BlockComponentPlayerInteractEvent): INTERACT_COMPONENT {
    /**
     * * 方块对象
     */
    const block = source.block;
    /**
     * * 方块状态
     */
    const state = source.block.permutation;
    /**
     * * 方块维度
     */
    const dimension = source.dimension;
    /**
     * * 玩家对象
     */
    const player = source.player;
    /**
     * * 玩家背包
     */
    const container = player?.getComponent('minecraft:inventory')?.container;
    /**
     * * 物品对象
     */
    const item = container?.getItem(player?.selectedSlotIndex ?? 0);
    // 返回 方块交互组件 的 解构
    return { block, state, dimension, player, container, item };
};
/**
 ** 计数模块
 */
export function CountingModuleTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 输入值
             */
            const input = analysis.state.getState('STATE:input') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:input', input != 10 ? input + 1 : 1);
            native_tools.TrySetPermutation(analysis.block, 'STATE:count', 1);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            // 显示悬浮文本
            derived_tools.FloatingTextDisplay(analysis.block, '<§l§e 计数模块 §r> : §l§9' + (input != 10 ? input + 1 : 1));
        }
    }
};
/**
 ** 交互终端
 */
export function controlPanelTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.hasTag(defaultTag)) {
                /**
                 ** 方块状态值
                 */
                const note = analysis.state.getState('STATE:rune_note') as number;
                // 赋值 方块状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', note != 7 ? note + 1 : 0);
                // 播放音效 与 粒子效果
                analysis.player?.playSound('tile.piston.out');
                // 显示悬浮文本
                switch (note) {
                    case 0:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§9 海蓝模式 §r]');
                        break;

                    case 1:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§4 赤焰模式 §r]');
                        break;

                    case 2:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§2 森绿模式 §r]');
                        break;

                    case 3:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§6 橙岩模式 §r]');
                        break;

                    case 4:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§5 紫雷模式 §r]');
                        break;

                    case 5:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 白星模式 §r]');
                        break;

                    case 6:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l§0 黑渊模式 §r]');
                        break;

                    case 7:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 虚无模式 §r]');
                        break;

                    default: break;
                }
            }
            else {
                /**
                 ** 方块状态值
                 */
                const note = analysis.state.getState('STATE:rune_note') as number;
                if (analysis.state.getState('STATE:stage') != 0) return;
                if (note != 0) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1);
                    analysis.player?.playSound('conduit.activate')
                    analysis.player?.sendMessage('| §l交互终端§r | : §6信号已发送');
                }
                else {
                    analysis.player?.playSound('random.click')
                    analysis.player?.sendMessage('| §l交互终端§r | : §4当前操作无法执行!§r\n| §l交互终端§r | : 使用§l§6 魔晶起子 §r调整| 信号类型 |');
                }
            }
        }
    }
};
/**
 ** 逻辑非门
 */
export function LogicInverterTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 输入值
             */
            const price = analysis.state.getState('STATE:price') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:price', price != 9 ? price + 1 : 1);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.sendMessage('| 参数设置 | : §l§e逻辑元件§r[§6 运行周期§r] -> §u' + (price != 9 ? price + 1 : 1));
        }
    }
};
/**
 ** 信号过滤
 */
export function signalFilteringTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 方块状态值
             */
            const note = analysis.state.getState('STATE:rune_note') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', note != 7 ? note + 1 : 0);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            // 显示设置文本
            switch (note) {
                case 0:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§9 海蓝模式 §r]');
                    break;

                case 1:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§4 赤焰模式 §r]');
                    break;

                case 2:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§2 森绿模式 §r]');
                    break;

                case 3:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§6 橙岩模式 §r]');
                    break;

                case 4:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§5 紫雷模式 §r]');
                    break;

                case 5:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 白星模式 §r]');
                    break;

                case 6:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l§0 黑渊模式 §r]');
                    break;

                case 7:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 虚无模式 §r]');
                    break;

                default: break;
            }
        }
    }
};
/**
 ** 打包投送
 */
export function PackageDeliveryTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 方块状态值
             */
            const face = analysis.state.getState('minecraft:block_face') as string;
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.in');
            // 赋值 方块状态
            switch (face) {
                case 'down':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'up');
                    break;
                case 'up':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'north');
                    break;
                case 'north':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'south');
                    break;
                case 'south':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'west');
                    break;
                case 'west':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'east');
                    break;
                case 'east':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'down');
                    break;

                default: break;
            }
        }
    }
};
/**
 ** 物资收集
 */
export function CollectionTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 方块状态值
             */
            const value = analysis.state.getState('STATE:value') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 4 ? value + 1 : 0);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.playSound('random.click');
            // 赋值 方块状态
            switch (value) {
                case 1:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 16 §r]');
                    break;
                case 2:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 24 §r]');
                    break;
                case 3:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 32 §r]');
                    break;
                case 4:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 8 §r]');
                    break;

                default: break;
            }
        }
    }
};
/**
 ** 参数设置
 */
export function ParameterTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 方块状态值
             */
            const value = analysis.state.getState('STATE:value') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 5 ? value + 1 : 0);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            // 显示 提示文本
            analysis.player?.sendMessage(
                {
                    rawtext: [
                        native_tools.BlockTranslate(analysis.block),
                        { text: `: 已修改至[§6 预设参数 §r]数值 -> ${value != 5 ? value + 1 : 0}` }
                    ]
                }
            );
        }
    }
};
/**
 ** 伺服基座
 */
export function SusceptorTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (!analysis.item?.hasTag(defaultTag)) return;
            /**
             ** 方块状态值
             */
            const value = analysis.state.getState('STATE:value') as number;
            // 赋值 方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 5 ? value + 1 : 0);
            // 播放音效 与 粒子效果
            analysis.player?.playSound('tile.piston.out');
            // 显示 提示文本
            analysis.player?.sendMessage(
                {
                    rawtext: [
                        native_tools.BlockTranslate(analysis.block),
                        { text: `: 已修改至[§6 最大负载 §r]参数 -> ${value != 5 ? value + 1 : 0}` }
                    ]
                }
            );
        }
    }
};
/**
 ** 水平机关门
 */
export function PlaneGateTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 根据符文类型决定是 开启 或 强制关闭
            if (analysis.state.getState('STATE:rune_type') == 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 7);
                analysis.player?.playSound('open.bamboo_wood_door');
            }
            else if (analysis.state.getState('STATE:rune_type') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                analysis.player?.playSound('open.bamboo_wood_door');
                machine_gate.Urgent(analysis.block);
            }
        }
    }
};
/**
 ** 垂直机关门
 */
export function VerticalGateTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) {
                analysis.player?.playSound('place.amethyst_block');
                machine_gate.AboveStacking(analysis.block);
                return;
            };
            // 根据符文类型决定是 开启 或 强制关闭
            if (analysis.state.getState('STATE:rune_type') == 0 && analysis.state.getState('STATE:about') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 7);
                analysis.player?.playSound('open.bamboo_wood_door');
            }
            else if (analysis.state.getState('STATE:rune_type') != 0 && analysis.state.getState('STATE:about') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                analysis.player?.playSound('open.bamboo_wood_door');
                machine_gate.Urgent(analysis.block);
            }
        }
    }
};
/**
 ** 魔晶上传
 */
export function PortalAboveTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:prompt_transport_above', analysis.block.bottomCenter());
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            analysis.player?.playSound('conduit.activate');
            machine_gate.AboveTeleport(analysis.block);
        }
    }
};
/**
 ** 魔晶下传
 */
export function PortalBelowTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:prompt_transport_below', analysis.block.center());
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            analysis.player?.playSound('conduit.activate');
            machine_gate.BelowTeleport(analysis.block);
        }
    }
};
/**
 ** 合金钢锅
 */
export function SpecialAlloyPotTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 判断玩家和玩家背包是否存在
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item) return;
            // 检测是否完成点火与装水
            if (analysis.state.getState('STATE:flame') == 1 && analysis.state.getState('STATE:water') == 1 && analysis.state.getState('STATE:count') == 9) {
                /**
                 ** 物品生成锚点
                 */
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter() as server.Vector3, { delimiter: ' ' });
                // 随机生成汤
                analysis.dimension.runCommand(`loot spawn ${anchor} loot random_soup`);
                // 重置方块状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:flame', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:water', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', 0);
                // 播放音效
                analysis.player?.playSound('bucket.empty_wate');
            }
            // 否则进行汤制作
            else if (analysis.state.getState('STATE:flame') == 1 && analysis.state.getState('STATE:water') == 1 && analysis.state.getState('STATE:count') != 9) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', analysis.state.getState('STATE:count') as number + 1);
                analysis.player?.playSound('random.swim');
            }
            // 否则进行点火 或 装水
            else switch (item?.typeId) {
                case 'minecraft:water_bucket':
                    analysis.dimension.spawnItem(new server.ItemStack('minecraft:bucket'), analysis.block.center());
                    analysis.player?.playSound('bucket.empty_water');
                    native_tools.TrySetPermutation(analysis.block, 'STATE:water', 1);
                    analysis.container.setItem(analysis.player.selectedSlotIndex);
                    break;

                case 'minecraft:flint_and_steel':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:flame', 1);
                    analysis.player?.playSound('fire.ignite');
                    break;
            }
        }
    }
};
/**
 ** 金属伪装
 */
export function MetalCamouflageTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 判断玩家和玩家背包是否存在
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item) return;
            // 修改方块纹理
            switch (item?.typeId) {
                case 'minecraft:gold_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:iron_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:emerald_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:diamond_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:lapis_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:netherite_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:copper_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;
                case 'minecraft:redstone_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 8);
                    break;

                default: break;
            };
            // 播放音效
            analysis.player?.playSound('fire.ignite');
        }
    }
};
/**
 ** 木质伪装
 */
export function WoodCamouflageTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 判断玩家和玩家背包是否存在
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container?.getItem(analysis.player.selectedSlotIndex);
            if (!item) return;
            // 修改方块纹理
            switch (item?.typeId) {
                case 'minecraft:oak_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:spruce_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:birch_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:jungle_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:acacia_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:dark_oak_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:mangrove_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;
                case 'minecraft:cherry_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 8);
                    break;
                case 'minecraft:bamboo_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 9);
                    break;
                case 'minecraft:crimson_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 10);
                    break;
                case 'minecraft:warped_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 11);
                    break;

                default: break;
            };
            // 播放音效
            analysis.player?.playSound('fire.ignite');
        }
    }
};
/**
 ** 石质伪装
 */
export function StoneCamouflageTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 判断玩家和玩家背包是否存在
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container?.getItem(analysis.player.selectedSlotIndex);
            if (!item) return;
            // 修改方块纹理
            switch (item?.typeId) {
                case 'minecraft:polished_basalt':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:polished_granite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:polished_diorite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:polished_andesite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:polished_blackstone':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:polished_deepslate':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:polished_tuff':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;

                default: break;
            };
            // 播放音效
            analysis.player?.playSound('fire.ignite');
        }
    }
};
/**
 ** 魔晶储罐
 */
export function CrystalTankTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            /**
             ** 获取玩家
             */
            const player = analysis.player;
            /**
             ** 获取玩家背包
             */
            const container = player?.getComponent('minecraft:inventory')?.container;
            /**
             ** 缓存值
             */
            const caching = analysis.state.getState('STATE:caching') as number;
            // 判断玩家是否满足触发条件
            if (!player || !container || !analysis.item?.getTags().includes('data_tag:energy_crystal.series')) return;
            // 判断物品是否属于 永恒魔晶石
            if (analysis.item?.getTags().includes('data_tag:eternal_crystal')) {
                /**
                 ** 恒常-魔晶储罐
                 */
                const constant = server.BlockPermutation.resolve('block_energy:constant_tank');
                // 播放音效与粒子效果
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter() as server.Vector3);
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter() as server.Vector3);
                analysis.player?.playSound('cauldron.explode');
                // 置换方块类型
                analysis.block.setPermutation(constant);
                // 清除物品
                native_tools.DeleteItemStack(container, new server.ItemStack(analysis.item.typeId));
            }
            else if (caching != 8) {
                // 赋值 方块状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:caching', caching + 1);
                // 播放音效 与 粒子效果
                player.playSound('block.end_portal_frame.fill');
                // 清除物品
                native_tools.DeleteItemStack(container, new server.ItemStack(analysis.item.typeId));
            }
            else if (caching == 8) {
                // 播放音效与粒子效果
                analysis.player?.playSound('mob.shulker.bullet.hit');
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter() as server.Vector3);
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter() as server.Vector3);
                // 显示提示
                analysis.player?.sendMessage('§c容器已满载, 无法继续填充')
                // 赋值 方块状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:output', 2);
            }
        }
    }
};
/**
 ** 熔岩质能
 */
export function MagmaPowerTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 判断玩家和玩家背包是否存在
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.item;
            // 检测物品
            if (!item || item?.typeId !== 'minecraft:lava_bucket') return;
            /**
             ** 获取方块状态
             */
            const magma = analysis.state.getState('STATE:magma') as number;
            // 检测是否已满载
            if (magma == 15) return;
            // 修改方块纹理
            native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
            // 播放音效
            analysis.player?.playSound('bucket.fill_lava');
            // 清除物品
            analysis.container.setItem(analysis.player.selectedSlotIndex);
            // 生成空铁桶
            native_tools.TrySpawnItem(analysis.dimension, new server.ItemStack('minecraft:bucket'), analysis.block.center());
        }
    }
};
/**
 ** 区块显示
 */
export function RegionDisplayTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 执行组件功能
            effect_machine.Display(analysis.block);
        }
    }
};
/**
 ** 诸界道标
 */
export function RoadSignPresetsTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 执行组件功能
            effect_machine.RoadSignPresets(analysis.block);
        }
    }
};
/**
 ** 附魔分离
 */
export function EnchantmentDissociationTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            /**
             ** 进行交互的玩家
             */
            const player = analysis.player;
            /**
             ** 机器下方的方块对象
             */
            const below = analysis.block.below();
            /**
             ** 机器下方的物品容器
             */
            const container = below?.getComponent('minecraft:inventory')?.container;
            /**
             ** 获取物品附魔
             */
            const enchantable = analysis.item?.getComponent('minecraft:enchantable');
            /**
             ** 获取全部附魔条目
             */
            const enchantments = enchantable?.getEnchantments();
            /**
             * * 尝试分离附魔书
             * 
             * @param {server.Enchantment[]} enchantments - 获取物品附魔条目
             * 
             * @param {server.Container} container - 机器下方的物品容器
             * 
             * @param {server.Block} block - 机器下方的方块对象
             * 
             * @param {server.ItemEnchantableComponent} enchantable - 获取物品附魔组件
             */
            function dissociation(enchantments: server.Enchantment[], container: server.Container, block: server.Block, enchantable?: server.ItemEnchantableComponent) {
                /**
                 ** 获取附魔条目的数量
                 */
                const number = enchantments.length;
                /**
                 ** 定于需要消耗的书本
                 */
                const blockItem = new server.ItemStack('minecraft:book', number);
                /**
                 ** 粒子显示锚点
                 */
                const anchor = math_tools.Vector.add(block.center(), { x: 0, y: 2, z: 0 });
                // 检测物品是否足够
                if (!native_tools.CheckItemStack(container, [blockItem])) return derived_tools.ErrorMessage('<§l§b 附魔分离 §r>§4 发生错误§r', block, { text: '未能在<§l§3 方块容器 §r>内获取到足够数量的<§l§u 书本 §r>' });
                // 判断能量是否足够
                if (!realm_property.ExpendEnergy(analysis.block, -number * 1000)) return;
                // 删除 普通书本 
                native_tools.DeleteItemStack(container, blockItem);
                // 添加 附魔书
                enchantments.forEach(
                    enchantment => {
                        /**
                         ** 附魔书的物品对象
                         */
                        const item = new server.ItemStack('minecraft:enchanted_book');
                        // 写入附魔效果
                        item.getComponent('minecraft:enchantable')?.addEnchantment(enchantment);
                        // 掉落 附魔书
                        native_tools.TrySpawnItem(block.dimension, item, block.center());
                    }
                );
                // 播放音效
                analysis.player?.playSound('block.enchanting_table.use');
                // 显示 粒子效果
                native_tools.TrySpawnParticle(block.dimension, 'constant:erupt_rune_purple', anchor);
                native_tools.TrySpawnParticle(block.dimension, 'constant:impact_rune_purple', anchor);
                native_tools.TrySpawnParticle(block.dimension, 'constant:excite_rune_purple', anchor);
                // 清除 物品附魔
                enchantable?.removeAllEnchantments();
            }
            // 检测方块与物品容器是否有效
            if (!below || !container) return derived_tools.ErrorMessage('<§l§b 附魔分离 §r>§4 发生错误§r', analysis.block, { text: '未能在设备下方找到合适的<§l§3 方块容器 §r>' });
            // 检测玩家与附魔是否有效
            if (!player || !enchantable || !enchantments) return;
            // 检测 附魔条目数量
            if (enchantments.length == 0) return;
            // 尝试分离附魔书
            dissociation(enchantments, container, below, enchantable);
            // 置换 玩家 手持的物品
            analysis.container?.setItem(player.selectedSlotIndex, analysis.item);
        }
    }
};
/**
 ** 星尘灌注
 */
export function StarEnergyInfusionTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            // 设定使用间隔
            if (!achieve_plan.ControlEventTrigger.BlockToken('消耗星尘力补充物品数值', analysis.block, 20)) return;
            /**
             * * 恢复物品耐久
             */
            function RestoreDurabilit() {
                /**
                 * * 获取物品耐久组件
                 */
                const durability = analysis.item?.getComponent('minecraft:durability');
                // 检测能量是否足够
                if (!durability || durability.damage == 0 || !realm_property.ExpendEnergy(analysis.block, -durability.damage * 5)) return;
                // 恢复耐久
                durability.damage = 0;
                // 置换 玩家 手持的物品
                analysis.container?.setItem(analysis.player?.selectedSlotIndex ?? 0, analysis.item);
                // 显示 特效
                ChargingSpecialEffects();
            };
            /**
             * * 恢复列车能量
             */
            function RestoreVehiclePower() {
                /**
                 ** 获取物品的能量属性
                 */
                const power = analysis.item?.getDynamicProperty('energy:offline_vehicle_power') as number ?? 3500;
                // 检测能量是否足够
                if (!realm_property.ExpendEnergy(analysis.block, 10000) || power >= 1000000) return;
                // 恢复列车能量
                analysis.item?.setDynamicProperty('energy:offline_vehicle_power', power + 10000);
                analysis.item?.setLore([`<§9§o§l 剩余能量 §r>: ${power + 10000}`]);
                // 置换 玩家 手持的物品
                analysis.container?.setItem(analysis.player?.selectedSlotIndex ?? 0, analysis.item);
                // 显示 特效
                ChargingSpecialEffects();
            };
            /**
             * * 显示 特效
             */
            function ChargingSpecialEffects() {
                /**
                 * * 定义 粒子参数
                 */
                const molang = new server.MolangVariableMap();
                /**
                 ** 粒子射流方向
                 */
                const direction = math_tools.Vector.difference(analysis.block.center(), analysis.player?.location ?? { x: 0, y: 0, z: 0 });
                // 设置 粒子参数
                molang.setFloat('variable.type', 0);
                molang.setVector3('variable.direction', direction);
                // 显示 粒子效果
                native_tools.TrySpawnParticle(analysis.block.dimension, 'scripts:path_ray', analysis.block.center(), molang);
                native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:erupt_rune_purple', analysis.block.center());
                native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:excite_rune_purple', analysis.block.center());
                // 播放音效
                analysis.player?.playSound('block.enchanting_table.use');
            };
            // 检测物品是否包含对应标签
            if (analysis.item?.hasTag('data_tag:use_energy_to_restore_vehicle_power')) return RestoreVehiclePower();
            if (analysis.item?.hasTag('data_tag:use_energy_to_restore_durability')) return RestoreDurabilit();
        }
    }
};
/**
 ** 曜石熔炉
 */
export function FurnaceTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            // 检测物品
            if (!item) return;
            if (item.typeId === 'block_unit:compressed_stone') {
                /**
                 ** 获取方块状态
                 */
                const material = analysis.state.getState('STATE:material') as number;
                if (material != 8) {
                    // 赋值方块状态
                    native_tools.TrySetPermutation(analysis.block, 'STATE:material', material + 1);
                    // 清除物品
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
                else analysis.player.onScreenDisplay.setTitle('§d剩余空间不足, 无法填充');
                // 播放音效
                analysis.player?.playSound('use.stone');
            };
            if (item.typeId === 'minecraft:bucket') {
                /**
                 ** 获取方块状态
                 */
                const magma = analysis.state.getState('STATE:magma') as number;
                /**
                 ** 物品生成锚点
                 */
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter() as server.Vector3, { delimiter: ' ' });
                // 检测方块状态
                if (magma == 0) analysis.player.onScreenDisplay.setTitle('§d储备不足, 无法提取');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/lava"`)
                    // 修改方块状态
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                    // 播放音效
                    analysis.player?.playSound('bucket.empty_lava');
                    // 清除物品
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            }
        }
    }
};
/**
 ** 曜石储罐
 */
export function StorageTankTrigger(): server.BlockCustomComponent {
    return {
        onPlayerInteract(source: server.BlockComponentPlayerInteractEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = InteractComponentTrigger(source);
            // 检测是否使用了正确道具
            if (analysis.item?.typeId == analysis.block.typeId) return;
            if (!analysis.player || !analysis.container) return;
            /**
             ** 当前手持物品
             */
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            // 检测物品
            if (!item) return;
            if (item.typeId === 'minecraft:bucket') {
                /**
                 ** 获取方块状态
                 */
                const magma = analysis.state.getState('STATE:magma') as number;
                /**
                 ** 物品生成锚点
                 */
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter() as server.Vector3, { delimiter: ' ' });
                // 检测方块状态
                if (magma == 0) analysis.player.onScreenDisplay.setTitle('§d熔岩不足, 无法提取');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/lava"`)
                    // 修改方块状态
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                    // 播放音效
                    analysis.player?.playSound('bucket.empty_lava');
                    // 清除物品
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            };
            if (item.typeId === 'minecraft:lava_bucket') {
                /**
                 ** 获取方块状态
                 */
                const magma = analysis.state.getState('STATE:magma') as number;
                /**
                 ** 物品生成锚点
                 */
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter() as server.Vector3, { delimiter: ' ' });
                // 检测方块状态
                if (magma == 15) analysis.player.onScreenDisplay.setTitle('§d容量不足, 无法填充');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/empty"`)
                    // 修改方块状态
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
                    // 播放音效
                    analysis.player?.playSound('bucket.fill_lava');
                    // 清除物品
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            };
        }
    }
};